
	  
using Youz.Common.BLL;
using Youz.Common.Helper;
using Youz.Common.Entity;
using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace Youz.CreditRepay.Manage.Handlers
{
    public partial class Lang_LanguageTypeHandler : IHttpHandler, IRequiresSessionState
    {
        HttpRequest request;
        Lang_LanguageTypeBLL bll = new Lang_LanguageTypeBLL();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            request = context.Request;

            string _type = request.QueryString["type"];
            string result = string.Empty;
            switch (_type)
            {
                case "get":
                    result = Get();
                    break;
                case "list":
                    result = List();
                    break;
                case "save":
                    result = Save();
                    break;
                case "delete":
                    Utility.AuthRequest();
                    result = Delete();
                    break;
            }

            context.Response.Write(result);
            context.Response.End();
        }

        private string Get()
        {
            String LanguageCode = request.Form["LanguageCode"];

            return bll.GetJson(LanguageCode);
        }

        private string List()
        {
            StringBuilder sb = new StringBuilder();

            return Utility.GetJsonByObjectHaveTime(bll.Gets());
        }

        private string Save()
        {
            string id = request.Form["_LanguageCode"];
            bool isAdd = true;
            Lang_LanguageType model = bll.Get(id);
            if (model == null)
            {
                model = new Lang_LanguageType();
                model.LanguageCode = request.Form["LanguageCode"];
                model.CreateTime = DateTime.Now;
                model.Creator = Utility.MemberAccount;
                isAdd = true;
            }
            else
            {
                isAdd = false;
            }
            model.LanguageName = request.Form["LanguageName"];
            model.Icon = WebHelper.Post<String>("Icon");
            model.DateFormat = WebHelper.Post<String>("DateFormat");
            model.IsEnable = WebHelper.Post<bool>("IsEnable");
            model.IsDefault = WebHelper.Post<bool>("IsDefault");
            model.ModifiedTime = DateTime.Now;
            model.Modifier = Utility.MemberAccount;
            if (isAdd ? bll.Add(model) : bll.Update(model))
            {
                return Utility.AjaxResult(true);
            }
            else
            {
                return Utility.AjaxResult(false);
            }
        }

        private string Delete()
        {
            if (bll.Delete(request.Form["LanguageCode"]))
            {
                return Utility.AjaxResult(true);
            }
            else
            {
                return Utility.AjaxResult(false);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

  